package com.zwz.controller;

import com.zwz.entity.SoftwareRegistry;
import com.zwz.service.SoftwareRegistryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/software")
public class SoftwareRegistryController {

    @Autowired
    private SoftwareRegistryService service;

    @PostMapping
    public ResponseEntity<?> create(@RequestBody SoftwareRegistry entity) {
        try {
//            service.create(entity);
            return ResponseEntity.ok("创建成功");
        } catch (IllegalArgumentException e) {
            return ResponseEntity.badRequest().body(e.getMessage());
        }
    }

    @GetMapping("/search")
    public ResponseEntity<List<SoftwareRegistry>> search(
            @RequestParam String name) {
        return ResponseEntity.ok(service.searchByName(name));
    }

    @DeleteMapping("/{id}")
    public ResponseEntity<?> delete(@PathVariable String id) {
        service.delete(id);
        return ResponseEntity.ok("删除成功");
    }
}